<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="../../include.inc.jsp"%>
<div class="row">
    <div class="col-lg-12">
        <form id="formDlg" class="form-horizontal" role="form">
            <input type="hidden" id="id" name="id" value="${hospital.id}" />
            <!-- 数据权限 --> 
            <input type="hidden" id="organizationId" name="organization.id" value="${organizationId}" />
            <div class="form-group">
                <label class="col-lg-2 control-label">医院名称:</label><span class="text-danger">*</span>
                <div class="col-lg-9">
                    <input type="text" class="form-control" id="name" name="name" value="${hospital.name}" maxlength="30"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label">医院级别:</label><span class="text-danger">*</span>
                <div class="col-lg-9">
                    <x:dictData dictCode="Hospital_Level" var="hospitalLevel">
                        <x:select var="level" items="${hospitalLevel}" id="level" name="level" className="form-control">
                            <x:option value="${level.code }" text="${level.name }" selected="${hospital.level eq level.code}"></x:option>
                        </x:select>
                    </x:dictData>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label">医院简介:</label>
                <div class="col-lg-9">
                    <textarea class="form-control" name="introduction">${hospital.introduction}</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label">详细地址:</label>
                <div class="col-lg-9">
                    <textarea class="form-control" name="address" maxlength="225">${hospital.address}</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label">省:</label>
                <div class="col-lg-9">
                    <select class="form-control" id="province" name="province.id" onchange="selectProvince(this);">
                        <option value="">请选择</option>
                        <c:forEach items="${provinces }" var="p">
                            <option value="${p.id }" <c:if test="${hospital.province.id eq p.id }">selected</c:if>
                            >${p.name }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label">市:</label>
                <div class="col-lg-9">
                    <select class="form-control" id="city" name="city.id" onchange="selectCity(this);">
                        <option value="">请选择</option>
                        <c:forEach items="${citys }" var="p">
                            <option value="${p.id }" <c:if test="${hospital.city.id eq p.id }">selected</c:if>
                            >${p.name }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label">区/县:</label>
                <div class="col-lg-9">
                    <select class="form-control" id="district"name="district.id">
                        <option value="">请选择</option>
                        <c:forEach items="${districts }" var="p">
                            <option value="${p.id }" <c:if test="${hospital.district.id eq p.id }">selected</c:if>
                            >${p.name }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    jQuery(function($) {
        $('#formDlg').validate({
            errorElement : 'span',
            errorClass : 'help-block',
            focusCleanup : false,
            focusInvalid : false,
            onsubmit : false,
            rules : {
                "name":{required:true},
                "level":{required:true}
            },
            messages : {
                "name" : '请输入医院名称',
                "level" : '请选择医院级别',
            },
            highlight : function(e) {
                $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
            },
            success : function(e) {
                $(e).closest('.form-group').removeClass('has-error').addClass('has-success');
                $(e).remove();
            },
        });
    });
    function selectProvince(obj){
    	if($(obj).val() != ""){
            $.ajax({
                url : "${contextPath}/manage/region/getRegionByPid/" + $(obj).val(),
                type : "post",
                success : function(data) {
                	initCity();
		    		initDistrict();
                    $(data.rows).each(function(i, o) {
                        $("#city").append("<option value=\""+o.id+"\">" + o.name+ "</option>");
                    });
                }
            });
    	}else{
    		initCity();
    		initDistrict();
    	}
    }
    function selectCity(obj){
    	if($(obj).val() != ""){
            $.ajax({
                url : "${contextPath}/manage/region/getRegionByPid/" + $(obj).val(),
                type : "post",
                success : function(data) {
                	initDistrict();
                    $(data.rows).each(function(i, o) {
                        $("#district").append("<option value=\""+o.id+"\">" + o.name+ "</option>");
                    });
                }
            });
    	}else{
    		initDistrict();
    	}
    }
    function initCity(){//初始化市select
    	$("#city").empty();
        $("#city").append("<option value=''>请选择</option>");
    }
    function initDistrict(){//初始化区select
    	$("#district").empty();
        $("#district").append("<option value=''>请选择</option>");
    }
</script>